<template>
	<view>
		
		<view v-if="loading">
			<howe-loading></howe-loading>
		</view>
		<view v-else>
			<howe-swiper></howe-swiper>
			<uni-notice-bar 
				:show-icon="true"
				:scrollable="true"
				:single="true" :text="noticeList[0].content"/>
			<view style="margin: 20rpx;">
				<uni-row class="demo-uni-row">
					<uni-col :span="1">
						<uni-icons type="fire-filled" size="20" color="red"></uni-icons>
					</uni-col>
					<uni-col :span="23">
						<text style="font-size: 40rpx; font-weight: 500;">最新发布</text>
					</uni-col>
				</uni-row>
			</view>
			<ad unit-id="adunit-39b53761b10c9de2" ad-type="video" ad-theme="white"></ad>
			<!--资源列表-->
				<uni-card is-full="true" v-for="(item,index) in resourceList" :key="index" @click="clickResource(item)">
					<template v-slot:cover>
							<image :src="item.imgFile" :mode="scaleToFill" @click="clickResource(item)"  style="height: 330upx; width: 100%;" ></image>
					</template>
					<uni-row >
						<uni-col :span="18">
							<text style="font-size: 35rpx; font-weight: bold; color: #555555">{{item.name}}</text>
						</uni-col>
						<uni-col :span="6">
								<uni-tag type="error" text="普通资源"></uni-tag>
						</uni-col>
					</uni-row>
					<uni-row >
						<uni-col :span="20">
							<text style="font-size: 25rpx;color: #555555">{{item.introduce.substr(0,20)+"..."}}</text>
						</uni-col>
						<uni-col :span="4">
								<text style="font-size: 20rpx; font-weight: 450; margin-top: 50upx; color: #555555;">{{item.updateTime}}</text>
						</uni-col>
					</uni-row>
				</uni-card>
				<!--网站列表-->
				<uni-card is-full="true" v-for="(item,index) in websiteList" :key="index" @click="clickWebsite(item)">
					<template v-slot:cover>
							<image :src="item.imgFile" :mode="scaleToFill" @click="clickWebsite(item)"  style="height: 330upx; width: 100%;" ></image>
					</template>
					<uni-row >
						<uni-col :span="18">
							<text style="font-size: 35rpx; font-weight: bold; color: #555555">{{item.name}}</text>
						</uni-col>
						<uni-col :span="6">
								<uni-tag type="primary" text="网站资源"></uni-tag>
						</uni-col>
					</uni-row>
					<uni-row >
						<uni-col :span="20">
							<text style="font-size: 25rpx;color: #555555">{{item.introduce.substr(0,20)+"..."}}</text>
						</uni-col>
						<uni-col :span="4">
								
								<text style="font-size: 20rpx; font-weight: 450; margin-top: 50upx; color: #555555;">{{item.updateTime}}</text>
						</uni-col>
					</uni-row>
				</uni-card>
			</view>
			<ad unit-id="adunit-06db7fd084d552ef"></ad>
		</view>
			

		
		
</template>

<script>
	export default {
		data() {
			return {
				loading: true,
				noticeList: [],
				noticeParam: {
					order: "desc",
					orderBy: "update_time",
					pageNum: 1,
					pageSize: 1,
					searchPARAM: {
						id: "",
						content: ""
					}
				},
				websiteList: [],
				websiteParam: {
					order: "desc",
					orderBy: "update_time",
					pageNum: 1,
					pageSize: 2,
					searchPARAM: {
						id: "",
						imgFile: "",
						introduce: "",
						name: "",
						type: "",
						url: "",
						isHide: 0,
					}
				},
				resourceList: [],
				resourceParam: {
					order: "desc",
					orderBy: "update_time",
					pageNum: 1,
					pageSize: 2,
					searchPARAM: {
						downloadUrl: "",
						id: "",
						imgFile: "",
						introduce: "",
						introduceUrl: "",
						name: "",
						type: "",
						downloadPassword: "",
						isHide: 0,
					}
				},

			}
		},
		created() {
			
			uni.request({
				url: this.$api + '/website/page',
				header: {
					'content-type': 'application/json' //自定义请求头信息
				},
				method: 'POST',
				data: this.websiteParam,
				//请求成功后返回
				success: (res) => {
					// 请求成功之后将数据给Info
					if (res.data.code === '200') {
						this.websiteList=res.data.data.records;
						this.websiteList.forEach((website) => {
							//时间截取
							website.updateTime=website.updateTime.slice(0,website.updateTime.indexOf(" "));
							website.imgFile = this.$api + '/img/' + website.imgFile
							console.log("website")
							
						})
						
					}
				},
				fail: (res) => {
					uni.showToast({
						title: "请求错误:"+res.errMsg,
						icon: 'none',
						duration: 850
					});
				}
			});
			
			
			uni.request({
				url: this.$api + '/resource/page',
				header: {
					'content-type': 'application/json' //自定义请求头信息
				},
				method: 'POST',
				data: this.resourceParam,
				//请求成功后返回
				success: (res) => {
					// 请求成功之后将数据给Info
					if (res.data.code === '200') {
						this.resourceList=res.data.data.records;
						this.resourceList.forEach((resource) => {
							//时间截取
							resource.updateTime=resource.updateTime.slice(0,resource.updateTime.indexOf(" "));
							resource.imgFile = this.$api + '/img/' + resource.imgFile
							console.log("resoure")
						})
					}
				},
				fail: (res) => {
					uni.showToast({
						title: "请求错误:"+res.errMsg,
						icon: 'none',
						duration: 850
					});
				}
			});
			
			
			uni.request({
				url: this.$api + '/notice/page',
				header: {
					'content-type': 'application/json' //自定义请求头信息
				},
				method: 'POST',
				data: this.noticeParam,
				//请求成功后返回
				success: (res) => {
					// 请求成功之后将数据给Info
					if (res.data.code === '200') {
						this.noticeList=res.data.data.records;
						console.log("notic")
						
					}
				},
				fail: (res) => {
					uni.showToast({
						title: "请求错误:"+res.errMsg,
						icon: 'none',
						duration: 850
					});
				}
			});
			setTimeout(() => {
				//设置延迟执行
				this.loading=false;
			}, 200);
			
		},
		methods: {
			clickWebsite(e) {
				
				uni.navigateTo({
					url: '/pages/websitepage/websitepage?id='+JSON.stringify(e.id)
				});
				// uni.redirectTo({
				//  	url: '/pages/websitepage/websitepage?id=' + JSON.stringify(e.id)
				//  })
			},
			clickResource(e) {
				uni.navigateTo({
					url: '/pages/resourcepage/resourcepage?id='+JSON.stringify(e.id)
				});
				// uni.redirectTo({
				//  	url: '/pages/resourcepage/resourcepage?id='+JSON.stringify(e.id)
				//  })
			},
			
			//分享朋友
			onShareAppMessage(res) {
				return {
					title: "howe科技",
					path: '/pages/index/index',
					imageUrl: "../../static/logo.png",
					
				}
			},
			//分享到朋友圈
			onShareTimeline(res) {
				return {
					title: "Howe科技-你的资源分享大全",
					path: '/pages/index/index',
					imageUrl: "../../static/logo.png",
				}
			},
			
			
			
		}

	}
</script>

<style>

</style>
